package model.forview;

import java.util.ArrayList;

import controllers.routes;

import model.wrap.node.Node;
import models.ConstantName;
import models.ConstantValue;

/**
 * 
 * @author pocteg
 * 
 */
public class NodeRelationModelForView extends ContentForMainTemplate
{

    /**
     * ----PRIVATE-----------ATTRIBUTS-----------INSTANCE----------------------
     */

    private Node node;
    
    private ArrayList<Node> parents;
    
    private ArrayList<Node> children;
    
    
    /**
     * ----PRIVATE-----------ATTRIBUTS-----------STATIC------------------------
     */

    /**
     * ----PROTECTED---------ATTRIBUTS-----------INSTANCE----------------------
     */

    /**
     * ----PROTECTED---------ATTRIBUTS-----------STATIC------------------------
     */

    /**
     * ----PUBLIC------------ATTRIBUTS-----------INSTANCE----------------------
     */

    /**
     * ----PUBLIC------------ATTRIBUTS-----------STATIC------------------------
     */

    /**
     * ----CONSTRUCTORS--------------------------------------------------------
     */

    /**
     * 
     * @param node
     */
    public NodeRelationModelForView(Node node)
    {
	setRelative(node);
	setDefaultValues();
    }

    /**
     * ----PRIVATE-----------METHOD-----------INSTANCE-------------------------
     */

    /**
     * @author pocteg
     */
    private void setDefaultValues()
    {
	String title = ConstantValue.getConstantValue(ConstantName.NODE_RELATION_PAGE_TITLE);
	String header = ConstantValue.getConstantValue(ConstantName.NODE_RELATION_PAGE_HEADER);
	String footer = ConstantValue.getConstantValue(ConstantName.NODE_RELATION_PAGE_FOOTER);
	String userName = "";

	title = title != null ? title : "Node create";
	header = header != null ? header : "Node create";
	footer = footer != null ? footer : "Node create";

	mainModelForView = new MainModelForView(title, userName, header, footer);
    }

    /**
     * Set other values
     * @author pocteg
     * @param node
     */
    private void setRelative(Node node)
    {
	this.node = node;	
	this.parents = node.getParents();
	this.children = node.getChildren();
    }

    
    
    /**
     * ----PRIVATE-----------METHOD-----------STATIC---------------------------
     */

    /**
     * ----PROTECTED---------METHOD-----------INSTANCE-------------------------
     */

    /**
     * ----PROTECTED---------METHOD-----------STATIC---------------------------
     */

    /**
     * ----PUBLIC------------METHOD-----------INSTANCE-------------------------
     */

    /**
     * Get size of parent
     * @author pocteg
     * @return
     */
    public int getParentsSize()
    {
	return this.parents.size();
    }
    
    /**
     * Get size of children
     * @author pocteg
     * @return
     */
    public int getChildrenSize()
    {
	return this.children.size();
    }
    
    /**
     * Get title of child.
     * @author pocteg
     * @param index
     * @return
     */
    public String getChildTitle(int index)
    {
	return this.children.get(index).getTitle();
    }
    
    /**
     * Get title of parent.
     * @author pocteg
     * @param index
     * @return
     */
    public String getParentTitle(int index)
    {
	return this.parents.get(index).getTitle();
    }
    
    /**
     * Get title of node.
     * @author pocteg
     * @return
     */
    public String getNodeTitle()
    {
	return this.node.getTitle();
    }
    
    public String getStructureTitle()
    {
	return this.node.getStructure().getTitle();
    }
    
    public Long getStructureId()
    {
	return this.node.getStructure().getId();
    }
    
    public Long getNodeId()
    {
	return this.node.getId();
    }
    
    /**
     * Link to /node/relative/add
     * @author pocteg
     * @return
     */
    public String getAddRelativeLink()
    {
	return routes.Hierarchy.getPageNodeRelationAdd(this.node.getId(), 0, 0).url();
    }
    
    
    public ArrayList<Node> getParents()
    {
	return this.parents;
    }
    
    public ArrayList<Node> getChildren()
    {
	return this.children;
    }
    /**
     * ----PUBLIC------------METHOD-----------STATIC---------------------------
     */

    /**
     * ----GETTERS--&--SETTERS-------------------------------------------------
     */

}
